//
//  WHMainTabBarController.swift
//  Weibo
//
//  Created by 胡碧涛 on 16/5/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class WHMainTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        addTabBarButtonItemControllers(WHHomeController(), title: "首页", imageName: "tabbar_home")
        addTabBarButtonItemControllers(WHMessageController(), title: "消息", imageName: "tabbar_message_center")
        addTabBarButtonItemControllers(WHDiscoverController(), title: "发现", imageName: "tabbar_discover")
        addTabBarButtonItemControllers(WHProfileController(), title: "我的", imageName: "tabbar_profile")
    }

    func addTabBarButtonItemControllers(_ childController: UIViewController, title: String, imageName: String) {
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        //  修改文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        //  设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: UIControlState())
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
    }
    
}

